<?php

namespace App\Api\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SellPackageDetailModel extends Model
{
    use HasFactory;

    protected $table = 'sell_package_detail';

    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    /**
     * $dates 数组内的列转换为日期格式
     *
     * @var array
     */
    protected $dates = [
        'sell_date'
    ];

    public function packageContent()
    {
        return SELF::hasMany(SellPackageContentModel::class, 'package_detail_id', 'id');
    }

    public function packageBatch()
    {
        return SELF::hasMany(SellPackageBatchModel::class, 'sell_package_content_id', 'id');
    }
}
